package vsm.vsm_server.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vsm.vsm_server.pojo.Comment.*;
import vsm.vsm_server.pojo.Result.Result;
import vsm.vsm_server.pojo.Result.ResultEnum;
import vsm.vsm_server.service.CommentService;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/comment")
@CrossOrigin
public class CommentController {
    @Autowired
    CommentService commentService;
    @PostMapping("/getByVideoId")
    public Result<CommentRootVo> getRootCommentByVideoId(@RequestBody RootCommentGetDto rootCommentGetDto){
        log.info("获取{}的评论", rootCommentGetDto.getVideoId());
        CommentRootVo commentRootVo = commentService.getRootCommentByVideoId(rootCommentGetDto);
        return Result.success(commentRootVo);
    }
    @PostMapping("/getChildComments")
    public Result<CommentChildVo> getChildCommentListByRootId(@RequestBody ChildCommentGetDto childCommentGetDto){
        log.info("获取{}的子评论", childCommentGetDto.getRootCommentId());
        CommentChildVo commentChildVo = commentService.getChildCommentListByRootId(childCommentGetDto);
        return Result.success(commentChildVo);
    }
    @PostMapping("/send")
    public Result<CommentDetail> sendComment(@RequestBody CommentSendDto commentSendDto){
        log.info("发送评论{}",commentSendDto);
        CommentDetail comment =  commentService.sendComment(commentSendDto);
        if(comment!=null){
            return Result.success(comment);
        }else{
            return Result.error_special(ResultEnum.COMMENT_SEND_WRONG);
        }
    }
}
